package com.atguigu.spzx.log.service.impl;

import com.atguigu.spzx.log.mapper.SysOperLogMapper;
import com.atguigu.spzx.log.service.SysOperLogService;
import com.atguigu.spzx.model.dto.sys.SysOperLogDto;
import com.atguigu.spzx.model.entity.sys.SysOperLog;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * title:
 * author: zgl
 * date: 2024/1/1
 * description：
 */
@Service
public class SysOperLogServiceImpl implements SysOperLogService {
    @Autowired
    private SysOperLogMapper sysOperLogMapper;

    @Override
    public PageInfo<SysOperLog> getLogList(Integer pageNum, Integer pageSize, SysOperLogDto sysOperLogDto) {
        //设置分页参数
        PageHelper.startPage(pageNum, pageSize);

        //查询数据库
        PageInfo<SysOperLog> pageInfo = new PageInfo<>(sysOperLogMapper.getLogList(sysOperLogDto));
        return pageInfo;
    }

    @Override
    public SysOperLog getLog(Long id) {
        return sysOperLogMapper.getLog(id);
    }

    @Override
    public void save(SysOperLog sysOperLog) {
        /*try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }*/
        sysOperLogMapper.save(sysOperLog);
    }

    @Async
    @Override
    public void asyncSave(SysOperLog sysOperLog) {
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        sysOperLogMapper.save(sysOperLog);
    }
}
